@extends('app.base')

@section('page_title')
  {{ $luo->name }}会员专区
@endsection

@section('content')
  <div class="top-header">
    <h3>会员专区</h3>
    <span class="go-back"><i class="fa fa-angle-left"></i></span>
  </div>
  <div class="page-menu">
    <a href="/luo/{{ $luo->id }}"><div class="active-menu">部落主页</div></a>
    <a href="/luo/{{ $luo->id }}/users"><div>部落诗友</div></a>
    <a href="/"><div>其他部落</div></a>
  </div>
  <div class="content">
    <div class="luo-header">
      <a href="/luo/{{ $luo->id }}/event"><div><img src="/images/add-event.png" />发起活动</div></a>
      <a href="/luo/{{ $luo->id }}/add_post"><div><img src="/images/add-post.png" />发布作品</div></a>
    </div>
    <div class="post-list">
    @foreach ($posts as $post)
      <div class="post">
        <a href="/posts/{{ $post->id }}">
          <h5>《{{ $post->title }}》</h5>
          <p class="post-author">作者:{{ $post->user->name }} 发表于{{ $post->created_at->format('m月d日 H点i分')}}</p>
          <p>{{ get_text_desc($post->content) }}</p>
        </a>
      </div>
    @endforeach
      <div class="more">查看更多</div>
      <input type="hidden" name="current_page" value="{{ $posts->currentPage() }}" />
      <input type="hidden" name="last_page" value="{{ $posts->lastPage() }}" />
    </div>
  </div>
@endsection

@section('page_script')
  <script>
$(function(){
  $('.more').on('click', function(){
    var currentPage = parseInt($('input[name=current_page]').val()),
        lastPage = parseInt($('input[name=last_page]').val());
    if(currentPage < lastPage){
      var target = currentPage + 1;
      window.location = '/luo/{{ $luo->id }}?page=' + target;
    }else{
      alert('没有更多的文章了');
    }
  })
})
  </script>
@endsection
